package com.state.impl;

import com.state.GumballMachine;
import com.state.face.State;

public class WinnerState implements State {
	GumballMachine gumballMachine;

	public WinnerState(GumballMachine gumballMachine) {
		this.gumballMachine = gumballMachine;
	}

	public void insertQuarter() {
		System.out.println("请等待，我们已经给你了你一糖了");
	}

	public void ejectQuarter() {
		System.out.println("请等待，我们已经给你了你一糖了");
	}

	public boolean turnCrank() {
		System.out.println("转动两次曲柄也不能给你两次糖果");
		return false;
	}

	public void dispense() {
		System.out.println("你是赢家，你会得到两个糖果");
		gumballMachine.releaseBall();
		if (gumballMachine.getCount() == 0) {
			gumballMachine.setState(gumballMachine.getSoldOutState());
		} else {
			gumballMachine.releaseBall();
			if (gumballMachine.getCount() > 0) {
				gumballMachine.setState(gumballMachine.getNoQuarterState());
			} else {
				System.out.println("对不起，没有糖果了");
				gumballMachine.setState(gumballMachine.getSoldOutState());
			}
		}
	}

	public String toString() {
		return "会给你两个糖果，因为你是赢家";
	}
}
